﻿<UserControl x:Class="MergeTool.UI.Views.MergetoolView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:mui="http://firstfloorsoftware.com/ModernUI"
             xmlns:viewModels="clr-namespace:MergeTool.UI.ViewModels"
             xmlns:helpers="clr-namespace:MergeTool.UI.Helpers"
             xmlns:core="clr-namespace:System;assembly=mscorlib"
             xmlns:mergeOptionsExns="clr-namespace:Microsoft.TeamFoundation.VersionControl.Common;assembly=Microsoft.TeamFoundation.VersionControl.Common"
             mc:Ignorable="d" 
             d:DesignHeight="1000" d:DesignWidth="1000">
    <UserControl.Resources>
        <ObjectDataProvider x:Key="MergeOptionEnum" MethodName="GetValues" ObjectType="{x:Type core:Enum}">
            <ObjectDataProvider.MethodParameters>
                <x:Type Type="mergeOptionsExns:MergeOptionsEx"/>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>

        <helpers:EnumMatchToBooleanConverter x:Key="EnumConverter" />
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
    </UserControl.Resources>

    <Grid Style="{StaticResource ContentRoot}">
        <ScrollViewer>
            <StackPanel MinWidth="200">
                <!--<TextBlock Text="Merging manager interface" Style="{StaticResource Heading2}" Margin="0,0,0,20" />-->

                <Grid>
                    <Grid.Resources>
                        
                    <Style TargetType="{x:Type mui:ModernButton}" BasedOn="{StaticResource {x:Type mui:ModernButton}}">
                        <Setter Property="EllipseDiameter" Value="30"/>
                        <Setter Property="IconWidth" Value="16"/>
                        <Setter Property="IconHeight" Value="16"/>
                        <Setter Property="Margin" Value="5"/>
                    </Style>
                        
                    </Grid.Resources>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <StackPanel Orientation="Horizontal" Grid.Row="0" Grid.Column="0">
                        <StackPanel Orientation="Vertical">
                            <GroupBox HorizontalAlignment="Left" VerticalAlignment="Top">
                                <GroupBox.Header>
                                    <Label>Verification section</Label>
                                </GroupBox.Header>
                                <StackPanel Orientation="Horizontal" Height="45" HorizontalAlignment="Center" VerticalAlignment="Top">
                                <StackPanel.Resources>
                                            <PathGeometry x:Key="UnavailableIcon">F1 M 38,19C 48.4934,19 57,27.5066 57,38C 57,48.4934 48.4934,57 38,57C 27.5066,57 19,48.4934 19,38C 19,27.5066 27.5066,19 38,19 Z M 38,23.75C 35.2116,23.75 32.6102,24.5509 30.4134,25.9352L 50.0648,45.5866C 51.4491,43.3898 52.25,40.7884 52.25,38C 52.25,30.13 45.87,23.75 38,23.75 Z M 23.75,38C 23.75,45.8701 30.1299,52.25 38,52.25C 40.7884,52.25 43.3897,51.4491 45.5865,50.0649L 25.9351,30.4136C 24.5509,32.6103 23.75,35.2117 23.75,38 Z</PathGeometry>
                                            <PathGeometry x:Key="NonUniqueIcon">F1 M 57.72,34L 54.0533,34L 53.0933,31.0133L 47.5967,31.0133L 46.6467,34L 43,34L 48.43,19.0667L 52.4133,19.0667L 57.72,34 Z M 52.1967,28.0267L 50.63,23.0767C 50.5078,22.7011 50.4233,22.2533 50.3767,21.7333L 50.2933,21.7333C 50.2667,22.1711 50.1789,22.6045 50.03,23.0333L 48.4333,28.0267L 52.1967,28.0267 Z M 19.2067,57L 19.2067,42.0667L 24.6667,42.0667C 26.34,42.0667 27.6261,42.3711 28.525,42.98C 29.4239,43.5889 29.8733,44.4467 29.8733,45.5533C 29.8733,46.3556 29.6,47.0572 29.0533,47.6583C 28.5067,48.2595 27.8078,48.6778 26.9567,48.9133L 26.9567,48.9567C 28.0367,49.0878 28.8994,49.4806 29.545,50.135C 30.1905,50.7895 30.5133,51.5867 30.5133,52.5267C 30.5133,53.9 30.02,54.9889 29.0333,55.7933C 28.0467,56.5978 26.6989,57 24.99,57L 19.2067,57 Z M 22.62,44.6267L 22.62,48.04L 24.0633,48.04C 24.7411,48.04 25.2744,47.8778 25.6633,47.5533C 26.0522,47.2289 26.2467,46.7822 26.2467,46.2133C 26.2467,45.1556 25.4478,44.6267 23.85,44.6267L 22.62,44.6267 Z M 22.62,50.6L 22.62,54.44L 24.4233,54.44C 25.1922,54.44 25.795,54.2639 26.2317,53.9117C 26.6683,53.5594 26.8867,53.0789 26.8867,52.47C 26.8867,51.8878 26.6722,51.4306 26.2433,51.0983C 25.8144,50.7661 25.2144,50.6 24.4433,50.6L 22.62,50.6 Z M 32.7629,19.736C 36.5904,18.6385 40.4806,18.7972 43.9928,19.9679L 41.1673,23.3352C 38.8262,22.8274 36.3294,22.8745 33.8654,23.5811C 28.7293,25.0538 24.9904,29.0322 23.5957,33.808L 30.9886,31.6881L 28.2461,36.6357L 18.6335,39.3921L 15.8771,29.7794L 18.6196,24.8318L 20.3662,30.923C 22.4775,25.6729 26.902,21.4166 32.7629,19.736 Z M 43.2371,56.264C 39.4095,57.3615 35.5193,57.2028 32.0071,56.032L 34.8326,52.6648C 37.1737,53.1726 39.6706,53.1255 42.1346,52.4189C 47.2707,50.9462 51.0095,46.9678 52.4043,42.192L 45.0114,44.3119L 47.7539,39.3643L 57.3665,36.6079L 60.1229,46.2206L 57.3804,51.1682L 55.6338,45.0769C 53.5225,50.3271 49.098,54.5834 43.2371,56.264 Z</PathGeometry>
                                            <PathGeometry x:Key="Baseless">F1 M 32.4113,38C 32.4113,38.1309 32.3817,38.2533 32.3742,38.3843L 45.9897,45.1862C 47.1549,44.2024 48.6467,43.586 50.2943,43.586C 53.9978,43.586 57,46.588 57,50.2909C 57,53.998 53.9978,57 50.2943,57C 46.5871,57 43.5887,53.998 43.5887,50.2909C 43.5887,50.1558 43.6183,50.0376 43.6258,49.9067L 30.0103,43.1047C 28.8414,44.0843 27.3533,44.7007 25.7056,44.7007C 22.0021,44.7007 19,41.7029 19,38C 19,34.2929 22.0021,31.2909 25.7056,31.2909C 27.3533,31.2909 28.8414,31.9116 30.0103,32.8954L 43.6258,26.0891C 43.6183,25.9582 43.5887,25.8358 43.5887,25.7007C 43.5887,22.002 46.5871,19 50.2943,19C 53.9978,19 57,22.002 57,25.7007C 57,29.4078 53.9978,32.4098 50.2943,32.4098C 48.6429,32.4098 47.1549,31.7934 45.9897,30.8053L 32.3742,37.6158C 32.3817,37.7425 32.4113,37.8649 32.4113,38 Z</PathGeometry>
                                </StackPanel.Resources>
                                    <mui:ModernButton IconData="{StaticResource UnavailableIcon}" Command="{Binding UnavailableBranchNamesCheck, Mode=OneWay}" ToolTipService.InitialShowDelay="500" ToolTip="Check for unavailable branch names.">
                                    </mui:ModernButton>
                                    <mui:ModernButton IconData="{StaticResource NonUniqueIcon}" Command="{Binding NonUniqueBranchNamesCheck, Mode=OneWay}" ToolTipService.InitialShowDelay="500" ToolTip="Check for non unique branch names.">
                                    </mui:ModernButton>
                                    <mui:ModernButton IconData="{StaticResource Baseless}" Command="{Binding BaselessBranchesCheck, Mode=OneWay}" ToolTipService.InitialShowDelay="500" ToolTip="Check for baseless merge branches.">
                                    </mui:ModernButton>
                                </StackPanel>
                            </GroupBox>
                            <StackPanel Orientation="Horizontal" Margin="0,10,0,0" >
                                <TextBlock>Merge selected?</TextBlock>
                                <CheckBox IsChecked="{Binding Source={StaticResource MainViewModel}, Path=IsMergeMultipleSpecifiedChangesets, 
                                UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Margin="10,0,0,0" />
                            </StackPanel>
                            <ScrollViewer>
                                <TextBox 
                              TextWrapping="Wrap"
                              AcceptsReturn="True"
                              Width="138"
                              Height="130" Margin="0,10"
                              ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                              ScrollViewer.VerticalScrollBarVisibility="Auto"
                              VerticalAlignment="Top"
                              HorizontalAlignment="Center"
                              IsEnabled="{Binding Source={StaticResource MainViewModel}, Path=IsMergeMultipleSpecifiedChangesets, Mode=OneWay}"
                                Text="{Binding Source={StaticResource MainViewModel},Path=ExplicitChangesetArray, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
                             />
                            </ScrollViewer>
                        </StackPanel>
                        <GroupBox Margin="15,0" HorizontalAlignment="Left" VerticalAlignment="Top">
                        <GroupBox.Header>
                            <Label Padding="0,0,0,1">Merge specific</Label>
                        </GroupBox.Header>
                        <StackPanel>
                            <Grid>
                                <Grid.Resources>
                                        <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
                                            <Setter Property="Margin" Value="3" />
                                        </Style>
                                        <Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource {x:Type TextBlock}}">
                                            <Setter Property="Margin" Value="0" />
                                        </Style>

                                        <Style x:Key="BranchPathVisibilityStyle" TargetType="{x:Type ListBox}">
                                            <Style.Triggers>
                                                <Trigger Property="IsEnabled" Value="False">
                                                    <Setter Property="Visibility" Value="Collapsed" />
                                                </Trigger>
                                                <Trigger Property="IsEnabled" Value="True">
                                                    <Setter Property="Visibility" Value="Visible" />
                                                </Trigger>
                                            </Style.Triggers>
                                            <Setter Property="Margin" Value="4,0" />
                                        </Style>

                                    </Grid.Resources>
                                    <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="110" />
                                    <ColumnDefinition MinWidth="250" />
                                </Grid.ColumnDefinitions>

                                <CheckBox Grid.Row="0" Grid.Column="0" IsChecked="{Binding Path=IsMergeSpecific, Mode=TwoWay}" Margin="5" />
                                    <Label Grid.Row="1" Grid.Column="0"  IsEnabled="{Binding Path=IsMergeSpecific, Mode=OneWay}" VerticalAlignment="Center">From:</Label>
                                    <StackPanel Grid.Row="1" Grid.Column="1">
                                        <TextBox Text="{Binding Path=ImmediateMergeObject.FromPath, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" MinWidth="150" IsEnabled="{Binding Path=IsMergeSpecific, Mode=OneWay}" />
                                        <!--<TextBox x:Name="Filter"/>-->
                                        <ScrollViewer>
                                            <ListBox Style="{StaticResource BranchPathVisibilityStyle}" MaxHeight="125" x:Name="FromBranchPaths" ItemsSource="{Binding Path=ImmediateMergeObject.AvailableBranches}" SelectedItem="{Binding Path=ImmediateMergeObject.SelectedBranchFrom}" IsEnabled="{Binding Path=ImmediateMergeObject.IsShowAutoCompleteFrom, Mode=OneWay}" ScrollViewer.VerticalScrollBarVisibility="Visible" >
                                                <ListBox.ItemTemplate>
                                                    <DataTemplate>
                                                        <StackPanel>
                                                            <TextBlock Text="{Binding }"/>
                                                        </StackPanel>
                                                    </DataTemplate>
                                                </ListBox.ItemTemplate>
                                            </ListBox>
                                        </ScrollViewer>
                                    </StackPanel>
                                    <!--<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Path=ImmediateMergeObject.FromPath, UpdateSourceTrigger=PropertyChanged}" MinWidth="150" IsEnabled="{Binding Path=IsMergeSpecific, Mode=OneWay}" />-->
                                    <Label Grid.Row="2" Grid.Column="0" IsEnabled="{Binding Path=IsMergeSpecific, Mode=OneWay}" VerticalAlignment="Center">To:</Label>
                                    <StackPanel Grid.Row="2" Grid.Column="1">
                                        <TextBox Text="{Binding Path=ImmediateMergeObject.ToPath, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" MinWidth="150" IsEnabled="{Binding Path=IsMergeSpecific, Mode=OneWay}" />
                                        <!--<TextBox x:Name="Filter"/>-->
                                        <ScrollViewer>
                                            <ListBox Style="{StaticResource BranchPathVisibilityStyle}" MaxHeight="125" x:Name="ToBranchPaths" ItemsSource="{Binding Path=ImmediateMergeObject.AvailableBranches}" SelectedItem="{Binding Path=ImmediateMergeObject.SelectedBranchTo}" IsEnabled="{Binding Path=ImmediateMergeObject.IsShowAutoCompleteTo, Mode=OneWay}" ScrollViewer.VerticalScrollBarVisibility="Visible" >
                                                <ListBox.ItemTemplate>
                                                    <DataTemplate>
                                                        <StackPanel>
                                                            <TextBlock Text="{Binding }"/>
                                                        </StackPanel>
                                                    </DataTemplate>
                                                </ListBox.ItemTemplate>
                                            </ListBox>
                                        </ScrollViewer>
                                    </StackPanel>
                                   <!-- <TextBox Grid.Row="2" Grid.Column="1" Text="{Binding Path=ImmediateMergeObject.ToPath, UpdateSourceTrigger=PropertyChanged}" MinWidth="150" IsEnabled="{Binding Path=IsMergeSpecific, Mode=OneWay}" />-->
                                    <Label Grid.Row="3" Grid.Column="0" IsEnabled="{Binding Path=IsMergeSpecific, Mode=OneWay}" VerticalAlignment="Center">MergeOption:</Label>
                                    <ComboBox Grid.Row="3" Grid.Column="1" Margin="3" Width="150" HorizontalAlignment="Left" SelectedItem="{Binding Path=ImmediateMergeObject.MergeOption, Mode=TwoWay}" ItemsSource="{Binding Source={StaticResource MergeOptionEnum}}" IsEnabled="{Binding Path=IsMergeSpecific, Mode=OneWay}" />
                                    <Label Grid.Row="4" Grid.Column="0" IsEnabled="{Binding Path=IsMergeSpecific, Mode=OneWay}" VerticalAlignment="Center">Comment pattern:</Label>
                                    <ScrollViewer Grid.Row="4" Grid.Column="1">  
                                <TextBox  Text="{Binding Path=ImmediateMergeObject.CheckinCommentPattern, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" IsEnabled="{Binding Path=IsMergeSpecific, Mode=OneWay}"                              
                            TextWrapping="NoWrap"
                              AcceptsReturn="False"
                              MaxWidth="350"
                              MinWidth="250"
                              MaxLines="2"
                              ScrollViewer.HorizontalScrollBarVisibility="Auto"
                              ScrollViewer.VerticalScrollBarVisibility="Disabled"
                              HorizontalAlignment="Left"
                                             />
                                    </ScrollViewer>
                                    <Label Grid.Row="5" Grid.Column="0" IsEnabled="{Binding Path=IsMergeSpecific, Mode=OneWay}" VerticalAlignment="Center">Skip changesets:</Label>
                                    <TextBox Grid.Row="5" Grid.Column="1" Text="{Binding Path=ImmediateMergeObject.ChangesetIdToStartFrom, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" MinWidth="60" HorizontalAlignment="Left" IsEnabled="{Binding Path=IsMergeSpecific, Mode=OneWay}" />
                                </Grid>
                        </StackPanel>
                    </GroupBox>
                    </StackPanel>

                    <StackPanel HorizontalAlignment="Right" Orientation="Vertical" Grid.Row="0" Grid.Column="1">
                        <StackPanel.Resources>
                            <PathGeometry x:Key="IsChangesToMerge">F1 M 25.3333,20.5833C 23.5844,20.5833 22.1667,22.0011 22.1667,23.75C 22.1667,25.4989 23.5844,26.9167 25.3333,26.9167C 27.0822,26.9167 28.5,25.4989 28.5,23.75C 28.5,22.0011 27.0822,20.5833 25.3333,20.5833 Z M 25.3333,15.8334C 29.7056,15.8334 33.2499,19.3778 33.2499,23.75C 33.2499,26.9964 31.296,29.7863 28.5,31.008L 28.5,44.9921C 31.296,46.2137 33.25,49.0037 33.25,52.25C 33.25,56.6223 29.7056,60.1667 25.3333,60.1667C 20.9611,60.1667 17.4167,56.6223 17.4167,52.25C 17.4167,49.0037 19.3706,46.2137 22.1666,44.9921L 22.1666,31.008C 19.3706,29.7863 17.4166,26.9964 17.4166,23.75C 17.4166,19.3778 20.9611,15.8334 25.3333,15.8334 Z M 25.3333,49.0834C 23.5844,49.0834 22.1667,50.5011 22.1667,52.25C 22.1667,53.9989 23.5844,55.4167 25.3333,55.4167C 27.0822,55.4167 28.5,53.9989 28.5,52.25C 28.5,50.5011 27.0822,49.0834 25.3333,49.0834 Z M 42.75,26.9167L 42.75,31.6667L 34.8333,23.75L 42.7499,15.8334L 42.7499,20.5834L 47.5,20.5834C 50.9978,20.5834 53.8333,23.4189 53.8333,26.9167L 53.8333,44.9921C 56.6293,46.2137 58.5833,49.0037 58.5833,52.25C 58.5833,56.6223 55.0389,60.1667 50.6666,60.1667C 46.2944,60.1667 42.75,56.6223 42.75,52.25C 42.75,49.0037 44.7039,46.2137 47.5,44.9921L 47.5,30.0833C 47.5,28.3344 46.0822,26.9167 44.3333,26.9167L 42.75,26.9167 Z M 50.6666,49.0834C 48.9177,49.0834 47.5,50.5011 47.5,52.25C 47.5,53.9989 48.9177,55.4167 50.6666,55.4167C 52.4155,55.4167 53.8333,53.9989 53.8333,52.25C 53.8333,50.5011 52.4155,49.0834 50.6666,49.0834 Z</PathGeometry>
                        </StackPanel.Resources>
                        <Button Command="{Binding StartMerge, Mode=OneWay}">
                            <TextBlock FontWeight="Bold" TextAlignment="Center">--&gt;Start Merging&lt;--</TextBlock>
                        </Button>
                        <mui:ModernButton Command="{Binding ChangesToMergeCheck, Mode=OneWay}" IconData="{StaticResource IsChangesToMerge}" ToolTipService.InitialShowDelay="500" ToolTip="Changes to merge?" HorizontalAlignment="Center">
                        </mui:ModernButton>

                        <TextBlock Margin="0,0,0,5">Select merge approach:</TextBlock>
                        <Grid HorizontalAlignment="Left">
                        <ItemsControl  ItemsSource="{Binding Path=MergeApproaches, Mode=OneWay}" Height="0" Margin="20,0">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Path=Name}"/>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                       <ComboBox  ItemsSource="{Binding Path=MergeApproaches, Mode=OneWay}" IsEnabled="{Binding Path=IsCanSubmitMergeFlow, Mode=OneWay}">
                            <ComboBox.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Path=Name}"/>
                                </DataTemplate>
                            </ComboBox.ItemTemplate>
                        </ComboBox>
                            </Grid>
                    </StackPanel>
                </Grid>

                <StackPanel Margin="0,10,30,0">
                    <RichTextBox MinWidth="650" MinHeight="400" Name="RichTextOutput" HorizontalAlignment="Left" Opacity="1">
                        <FlowDocument Name="RichTextFlowOutput" LineHeight="20">
                            <Paragraph>
                                There will go output...
                            </Paragraph>
                        </FlowDocument>
                    </RichTextBox>
                </StackPanel>
            </StackPanel>
        </ScrollViewer>
    </Grid>
</UserControl>
